<!--
  Copyright © 2015 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<div class="modal-header clearfix">
  <h3 class="pull-left">{{heading}}</h3>
  <a class="btn pull-right" ng-click="$close()">
    <span class="fa fa-remove"></span>
    <span class="sr-only"> Close </span>
  </a>
</div>

<div class="modal-body">

  <form ng-show="preferences.length > 0">
    <div class="form-group row">
      <div class="col-xs-12">
        <div ng-repeat="preference in preferences" class="h4" ng-keypress="enter($event, $last)">
          <div class="row">
            <div class="col-sm-4">
              <input type="text"
                class="pref-key form-control"
                ng-model="preference.key"
                placeholder="key"
                my-focus-watch="$last" />
            </div>
            <div class="col-sm-7">
              <input type="text" class="form-control" ng-model="preference.value" placeholder="value"/>
            </div>
            <div class="col-sm-1">
              <a href="" class="btn btn-danger" ng-click="removePreference(preference)">
                <span class="fa fa-fw fa-trash"> </span>
              </a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </form>

  <div ng-show="preferences.length === 0">
    <div class="well well-sm text-center h4">
      <button class="btn btn-default" ng-click="addPreference()">
        <span class="fa fa-fw fa-plus"></span> Add Preference
      </button>
    </div>
  </div>

  <div class="row">
    <div class="col-xs-12">
      <button class="btn btn-primary pull-left" ng-click="addPreference()" ng-hide="preferences.length === 0">
        <span class="fa fa-fw fa-plus"></span>
      </button>

      <div class="pull-right">
        <button class="btn btn-default" ng-click="loadProperties()">Reset</button>
        <button class="btn btn-success" ng-click="save()" >Save</button>
      </div>
    </div>
  </div>

  <div class="system-preferences" ng-if="systemPreferences.length > 0">
    <hr/>
    <div class="table-responsive">
      <table class="table table-curved" cask-sortable>
        <thead>
          <tr ng-class="{'sort-enabled': systemPreferences.length>0}">
            <th data-predicate="key">Name</th>
            <th data-predicate="value">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="pref in systemPreferences | orderBy:sortable.predicate:sortable.reverse">
            <td>{{ pref.key }}</td>
            <td>{{ pref.value }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>

</div>
